package com.lxh.lxhcrm.controller.aftersale;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lxh.lxhcrm.model.pojos.*;
import com.lxh.lxhcrm.model.service.WorkordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 开发团队 ：lxh
 * 开发人员 ：李兴洋
 * 开发时间 ：2020年3月25日14:16:36
 * 类的名称 ：WorkordController
 * 类的描述 ：维修工单
 */
@RestController
@RequestMapping("/after-sale/workord")
public class WorkordController {
    @Autowired
    WorkordService workordService;

    //工单列表
    @RequestMapping("/workord-list")
    public Map<String, Object> workordList(Integer page , Integer size , String search , String kcName){
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Workord> allWorkord = workordService.findAllWorkord(search, kcName);

        Map<String,Object> kMap = new HashMap<>();
        kMap.put("total",obj.getTotal());
        kMap.put("rows",allWorkord);
        return kMap;
//
//        System.out.println("1=>"+page);
//        System.out.println("1=>"+size);
//        System.out.println("1=>"+search);
//        System.out.println("1=>"+kcName);
    }

    //总控台列表
    @RequestMapping("/allworkord-list")
    public List<Map> allworkordList(){

        return workordService.findAllWorkordByTname();
    }

    //添加工单
    @RequestMapping("/add-workord")
    @ResponseBody
    public Map<String,Object> addComplaint(@RequestBody Workord workord){
        Workord resWorkord = workordService.addWorkord(workord);
        Map<String,Object> kMap = new HashMap<>();
        kMap.put("resWorkord",resWorkord.getWorkordId());
        return kMap;
    }

    //删除工单
    @RequestMapping("/delete-workord")
    @ResponseBody
    public void deleteWorkord(Integer wId){
        workordService.deleteWorkord(wId);
    }

    //添加工单详情
    @RequestMapping("/add-serDetail")
    @ResponseBody
    public void addSerDetail(@RequestBody SerDetail serDetail){
        workordService.addSerDetail(serDetail);
    }

    //添加费用详情
    @RequestMapping("/add-costRecord")
    @ResponseBody
    public void addCostRecord(@RequestBody CostRecord costRecord){
        workordService.addCostRecord(costRecord);
    }

    @RequestMapping("/serDetailforWorkordId")
    public SerDetail findSerDetailByWid(Integer workordId){return workordService.findSdByWid(workordId);}

    @RequestMapping("/costRecordforWorkordId")
    public CostRecord findCostRecordByWid(Integer workordId){return workordService.findCRByWid(workordId);}

    //客户买过的商品
    @RequestMapping("/proListforCus")
    public List<Product> findProListByCusId(Integer customerId){
        return workordService.findProByCusId(customerId);
    }

    //合同中的客户
    @RequestMapping("/proCusforContract")
    public List<Map<String,Object>> findCusForContract(){
        return workordService.findCusForContract();
    }

    /** 所有维修状态**/
    @RequestMapping("/weiStateList")
    public List<WeiState> allWeiState(){
        return workordService.allWeiState();
    }

    /** 新增维修状态**/
    @RequestMapping("/add-weiState")
    @ResponseBody
    public void addWeiState (WeiState ws){
        workordService.addWeiState(ws);
    }

    /** 删除维修状态**/
    @RequestMapping("/delete-weiState")
    @ResponseBody
    public void deleteWeiState(Integer wsId){
        workordService.deleteWeiState(wsId);
    }

    /** 审批**/
    @RequestMapping("/workordCheck")
    @ResponseBody
    public void workordCheck(Integer wId){
        workordService.workordCheck(wId);
    }

    /** 修改维修状态**/
    @RequestMapping("/updateWeiState")
    @ResponseBody
    public void updateWeiState(String weiState,Integer workordId){
        workordService.updateWeiState(weiState,workordId);
    }


}
